﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="Core.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2011
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.Render.
//
//   starLiGHT.Render is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   starLiGHT.Render is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.
//
//   You should have received a copy of the GNU Lesser General Public License
//   along with starLiGHT.Render. If not, see http://www.gnu.org/licenses/.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.Render are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev::                       $:  Revision of last commit *
// * $Author::                    $:  Author of last commit   *
// * $Date::                      $:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.Render
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using starLiGHT.Light;
    using starLiGHT.Scene;
    #endregion

    public class Core
    {
        private IRenderer renderer;
        private SceneManager sceneManager;

        public Core(SceneManager sceneManager)
        {
            if (sceneManager == null)
            {
                throw new ArgumentNullException("sceneManager");
            }

            this.sceneManager = sceneManager;
        }

        public Core(IRenderer renderer, SceneManager sceneManager)
            : this(sceneManager)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException("renderer");
            }

            this.renderer = renderer;
        }

        public IRenderer Renderer
        {
            get { return this.renderer; }
        }

        public LightManager LightManager
        {
            get { return this.sceneManager.LightManager; }
        }

        public SceneManager SceneManager
        {
            get { return this.sceneManager; }
        }

        public void AddObject(ISceneObject sceneObject)
        {
            if (sceneObject == null)
            {
                throw new ArgumentNullException("sceneObject");
            }

            if (this.sceneManager == null)
            {
                throw new Exception("No SceneManager available at starLiGHT.Render.Core. Can't add the object.");
            }

            this.sceneManager.AddSceneObject(sceneObject);
        }

        public void Update(GameTime gameTime)
        {
            if (this.sceneManager != null)
            {
                this.sceneManager.Update(gameTime);
            }
        }

        public void Draw(GameTime gameTime)
        {
            if (this.renderer != null)
            {
                this.renderer.PreRender(this);

                this.renderer.Render(this);

                this.renderer.PostRender(this);
            }
        }
    }
}
